﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Linq;
using System.Threading.Tasks;
using VOL.Core.Utilities;
using VOL.Entity.DomainModels;
using VOL.Team.IServices;
using VOL.Team.TeamIservices.MaterialManagement.IServices;

namespace VOL.WebApi.Controllers.Team.xzc
{
    /// <summary>
    /// 物料管理
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MaterialManagementController : ControllerBase
    {
        /// <summary>
        /// 物料台账
        /// </summary>
        private readonly IMaterialLedgersService _materialLedgersService;

        public MaterialManagementController(IMaterialLedgersService materialLedgersService)
        {
            _materialLedgersService = materialLedgersService;
        }
        /// <summary>
        /// 查询物料台账-xzc
        /// </summary>
        /// <returns></returns>
        [HttpGet]
        public WebResponseContent GetMaterialLedger(string? qecode)
        {
            WebResponseContent webResponseContent = new WebResponseContent();
            var materialledgerList = _materialLedgersService.GetMaterialLedger(qecode);
            return webResponseContent.OK("查询物料台账成功", materialledgerList);
        }
        /// <summary>
        /// 新增物料台账-xzc
        /// </summary>
        /// <param name="materialledger"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebResponseContent> AddMaterialLedger([FromBody]MaterialLedger materialledger)
        {
            WebResponseContent webResponseContent = new WebResponseContent();
            int materialledgerList = await _materialLedgersService.AddMaterialLedger(materialledger);
            return webResponseContent.OK("新增物料台账成功", materialledgerList);
        }
        /// <summary>
        /// 更新物料台账-xzc
        /// </summary>
        /// <param name="materialledger"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebResponseContent> UpdateMaterialLedger([FromBody]MaterialLedger materialledger)
        {
            WebResponseContent webResponseContent = new WebResponseContent();
            int materialledgerList = await _materialLedgersService.UpdateMaterialLedger(materialledger);
            return webResponseContent.OK("更新物料台账成功", materialledgerList);
        }
        /// <summary>
        /// 删除物料台账-xzc
        /// </summary>
        /// <param name="materialledger"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebResponseContent> DeleteMaterialLedger(int id)
        {
            WebResponseContent webResponseContent = new WebResponseContent();
            int materialledgerList = await _materialLedgersService.DeleteMaterialLedger(id);
            return webResponseContent.OK("更新物料台账成功", materialledgerList);
        }
        /// <summary>
        /// 批量删除物料台账
        /// </summary>
        /// <param name="Id"></param>
        /// <returns></returns>
        [HttpPost]
        public async Task<WebResponseContent> DeleteAnageMaterialLedger(string Id)
        {
            WebResponseContent webResponseContent = new WebResponseContent();
            int materialledgerList = await _materialLedgersService.DeleteAnageMaterialLedger(Id);
            return webResponseContent.OK("批量删除物料台账成功", materialledgerList);
        }
    }
}
